@echo off

if "%1" == "" goto syntax_error
rem if "%2" == "" goto syntax_error
rem if "%3" == "" goto syntax_error

set TOOL_DBSERVER=%1
set TOOL_DBACCOUNT=aaa
set TOOL_DBPASSWORD=aaa
set TOOL_DBNAME=Parvis

@call CreateDatabase %TOOL_DBSERVER% %TOOL_DBACCOUNT% %TOOL_DBPASSWORD%
if errorlevel 1 goto sql_error

@call CreateSPAssembly %TOOL_DBSERVER% %TOOL_DBNAME% %TOOL_DBACCOUNT% %TOOL_DBPASSWORD%
if errorlevel 1 goto sql_error

@call CreateTables %TOOL_DBSERVER% %TOOL_DBNAME% %TOOL_DBACCOUNT% %TOOL_DBPASSWORD%
if errorlevel 1 goto sql_error

@call CreateViews %TOOL_DBSERVER% %TOOL_DBNAME% %TOOL_DBACCOUNT% %TOOL_DBPASSWORD%
if errorlevel 1 goto sql_error

@call CreateStoredProcedures %TOOL_DBSERVER% %TOOL_DBNAME% %TOOL_DBACCOUNT% %TOOL_DBPASSWORD%
if errorlevel 1 goto sql_error

@call InsertBaseData %TOOL_DBSERVER% %TOOL_DBNAME% %TOOL_DBACCOUNT% %TOOL_DBPASSWORD%
if errorlevel 1 goto sql_error

@call CreateUsers %TOOL_DBSERVER% %TOOL_DBNAME% %TOOL_DBACCOUNT% %TOOL_DBPASSWORD%
if errorlevel 1 goto sql_error

@call CreateJobs %TOOL_DBSERVER% %TOOL_DBNAME% %TOOL_DBACCOUNT% %TOOL_DBPASSWORD%
if errorlevel 1 goto sql_error


@echo *************************************************************
@echo *
@echo * Database Parvis successfully setup.
@echo *
@echo *************************************************************
goto end


:syntax_error
@echo *************************************************************
@echo *
@echo * Syntax error!
@echo * Required parameter is missing.
@echo *
@echo * Usage: SetupDatabase 'DatabaseServerName' 'Account' 'Password'
@echo *
@echo *************************************************************
goto end


:sql_error
@echo *************************************************************
@echo *
@echo * An sql error occured!
@echo *
@echo * See error message for more information
@echo *
@echo *************************************************************
goto end

:end
pause
